﻿using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Http;
using System;

namespace SingleBlog
{
    public static class HtmlExtension
    {
        /// <summary>
        /// 转换成绝对地址
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static string ToAbsoluteUrl(this HttpRequest request)
        => $"{request.Scheme}://{request.Host.ToUriComponent()}{request.Path.ToUriComponent()}";

        public static IHtmlContent ToTrueFalseBadge(this bool value, string trueText = "是", string falseText = "否")
            => new HtmlContentBuilder().AppendHtml("<span class='badge badge-{0}'>{1}<span>".StringFormat((value ? "success" : "danger"), value ? trueText : falseText));
    }
}
